package pwd.allen;

import lombok.Data;

import java.io.*;
import java.util.Date;
import java.util.List;

/**
 * @author lenovo
 * @create 2020-01-19 16:22
 **/
@Data
public class Person implements Cloneable, Serializable {
    private String name;
    private Integer age;
    private Date birthday;
    private List<Role> roles;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Object deepClone() throws IOException, ClassNotFoundException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(this);//需要支持序列化哦

        ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
        return objectInputStream.readObject();
    }
}
